//
//  FPNextViewController.m
//  Gunz
//
//  Created by Joggy on 16/2/1.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "FPNextViewController.h"

static NSString *accountName = @"";

@implementation FPNextViewController

-(void)viewDidLoad {
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [tap addTarget:self action:@selector(endEdit)];
    [self.view addGestureRecognizer:tap];
}

-(void)prepareForNav {
    [super prepareForNav];
    self.title = @"找回密码";
    //返回按键
    UIImage *leftImage = [UIImage imageNamed:@"all_back"];
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, (leftImage.size.width/leftImage.size.height)*22, 22)];
    [leftButton setImage:leftImage forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    [self navigationItem].leftBarButtonItem = leftBarItem;
}

-(void)prepareForLayout {
    [super prepareForLayout];
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - BBViewHeight)];
    scroll.contentSize = CGSizeMake(screenWidth, scroll.frame.size.height + 1);
    scroll.delegate = self;
    UIView *accountView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 66, FPNTextHeihgt)];
    //label
    accountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 66, 66)];
    NSMutableAttributedString *accountTitle = [[NSMutableAttributedString alloc] initWithString:@"账尼玛号 : "];
    NSRange titleRange1 = {0, accountTitle.length};
    NSRange titleRange2 = {1, 2};
    [accountTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font15*proportion] range:titleRange1];
    [accountTitle addAttribute:NSForegroundColorAttributeName value:[UIColor clearColor] range:titleRange2];
    accountLabel.attributedText = accountTitle;
    accountLabel.alpha = 0.7;
    [accountLabel sizeToFit];
    accountLabel.layer.position = CGPointMake(accountLabel.frame.size.width/2, accountView.frame.size.height/2);
    [accountView addSubview:accountLabel];
    //账号
    account = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 66, 66)];
    accountTitle = [[NSMutableAttributedString alloc] initWithString:accountName];
    NSRange titleRange3 = {0, accountTitle.length};
    [accountTitle addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:font15*proportion] range:titleRange3];
    account.attributedText = accountTitle;
    [account sizeToFit];
    account.layer.position = CGPointMake(accountLabel.frame.size.width + account.frame.size.width/2, accountLabel.layer.position.y);
    [accountView addSubview:account];
    //调整accountView
    accountView.frame = CGRectMake(0, 0, accountLabel.frame.size.width + account.frame.size.width, FPNTextHeihgt);
    accountView.layer.position = CGPointMake(screenWidth/2, accountView.frame.size.height/2 + FPNInsert);
    [scroll addSubview:accountView];
    //验证码视图
    UIView *veriView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 66, FPNTextHeihgt)];
    //验证码按键
    veriButton = [UIButton buttonWithType:UIButtonTypeSystem];
    veriButton.frame = CGRectMake(0, 0, FPNButtonWidth, FPNTextHeihgt);
    NSMutableAttributedString *idTitle = [[NSMutableAttributedString alloc] initWithString:@"点击获取验证码"];
    NSRange idRange = {0, idTitle.length};
    [idTitle addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:font11*proportion] range:idRange];
    [idTitle addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:idRange];
    [veriButton setAttributedTitle:idTitle forState:UIControlStateNormal];
    [veriButton setBackgroundColor:[UIColor colorWithRed:0.3 green:0.69 blue:0.51 alpha:1]];
    [veriView addSubview:veriButton];
    //验证码输入框
    veriText = [[UITextField alloc] initWithFrame:CGRectMake(veriButton.frame.size.width + FPNInsert/4, 0, FPNTextWidth, FPNTextHeihgt)];
    veriText.layer.borderColor = TEXT_BORDER_COLOR.CGColor;
    veriText.layer.borderWidth = 1;
    veriText.layer.cornerRadius = 6;
    veriText.font = [UIFont systemFontOfSize:font14*proportion];
    veriText.placeholder = @"请输入验证码";
    veriText.backgroundColor = [UIColor whiteColor];
    veriText.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, FPNInsert/4, FPNTextHeihgt)];
    veriText.leftViewMode = UITextFieldViewModeAlways;
    [veriView addSubview:veriText];
    //调整验证码视图
    veriView.frame = CGRectMake(0, 0, veriText.frame.origin.x + veriText.frame.size.width, FPNTextHeihgt);
    veriView.layer.position = CGPointMake(screenWidth/2, accountView.frame.origin.y + accountView.frame.size.height + veriView.frame.size.height/2 + FPNInsert/2.5);
    [scroll addSubview:veriView];
    //调整账户名视图
    CGRect temp = accountView.frame;
    temp.origin.x = veriView.frame.origin.x;
    accountView.frame = temp;
    [self.view addSubview:scroll];
    //底部按键
    veriBarButton = [[BarButtonView alloc] initWithFrame:CGRectMake(0, screenHeight - 64 - BBViewHeight, screenWidth, BBViewHeight) name:@"验证"];
    [veriBarButton.but addTarget:self action:@selector(verificate) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:veriBarButton];
}

-(void)passAccount:(NSString *)passAccount {
    accountName = passAccount;
}

-(void)back {
    [self.navigationController popViewControllerAnimated:true];
}

-(void)verificate {
    FPVeriViewController *veri = [[FPVeriViewController alloc] init];
    [veri passAccount:accountName];
    [self.navigationController pushViewController:veri animated:true];
}

-(void)endEdit {
    [self.view endEditing:true];
}

-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView {
    [self endEdit];
}

@end
